module TA = $(TA_DECL)
open TA

type ttree
external init_ttree: string -> string -> ttree = "init_ttree_$(TA_DECL)"
external get_n: ttree -> int64 = "get_n_$(TA_DECL)"
external get_event: int64 -> ttree -> ttree_decl  = "get_event_$(TA_DECL)"

let convert file_name tree_name ~to_directory =
    let ttree = init_ttree file_name tree_name in
    let module FE = Db_dir.WRITE_EVENTS
        (struct
            type serialized = ttree_decl
            let n_events = get_n ttree
            let get n = get_event n ttree
        end)
    in
    FE.write to_directory
;;
open Glob
let iter (f: ttree_decl -> unit) ~ttree_name file_name =
        let ttree = init_ttree file_name ttree_name in
        let n = get_n ttree in
        Cycle.iter ~from:0L (function
           | k when k < n -> 
                f (get_event k ttree); `Continue (Int64.add k 1L)
           | _ -> `End)

(*        for k = 1L to n do
                f (get_event k ttree)
        done*)
